//
//  MeetingViewBuilder.m
//  Rongcloud
//
//  Created by LiuLinhong on 2017/08/14.
//  Copyright © 2017年 Beijing Rongcloud Network Technology Co. , Ltd. All rights reserved.
//

#import "MeetingViewBuilder.h"
#import "MeetingViewController.h"
#import "MeetingCollectionViewItem.h"
#import "LeftMVControlCollectionViewItem.h"
#import "RightMVTableViewCellView.h"
#import "CommonUtility.h"

@interface MeetingViewBuilder ()

@property (nonatomic, strong) MeetingViewController *meetingViewController;

@end

@implementation MeetingViewBuilder

- (instancetype)initWithViewController:(NSViewController *)vc
{
    self = [super init];
    if (self)
    {
        self.meetingViewController = (MeetingViewController *) vc;
        [self initCallingBreathView];
        [self initVideoView];
        [self initMeetingControlView];
        [self initOperationCollectionView];
        [self initLeftMessageContentView];
        [self initRightMemberContentView];
        [self initConfirmMessageWindow];
        [self initAlertMessageWindow];
//        [self initConfirmMessagePanel];
//        [self initAlertMessagePanel];
//        [self initWhiteBoardWebView];
        [self initScreenShareMessageTextField];
        [self initAVInfoPanel];
    }
    return self;
}

- (void)reloadMeetingViewToFullScreen
{
    self.callingBreathImageView.frame = CGRectMake(kScreenWidth - 20 - 164 - 200, self.meetingViewController.mainView.frame.size.height - 20 - 164, 164, 164);
    self.callingHeadImageView.frame = CGRectMake((self.callingBreathImageView.frame.size.width-92)/2, (self.callingBreathImageView.frame.size.height-92)/2, 92, 92);
    self.callingHungUpButton.frame = CGRectMake(self.callingBreathImageView.frame.origin.x, self.callingBreathImageView.frame.origin.y - 30, 46, 46);
    self.callingAcceptButton.frame = CGRectMake(self.callingBreathImageView.frame.origin.x + self.callingBreathImageView.frame.size.width - 46, self.callingBreathImageView.frame.origin.y - 30, 46, 46);
//    [self.meetingViewController stopCallingBreath];
    
    CGFloat rightOperationViewWidth = 840 - kVideoWidth;
    CGFloat videoViewWidth = kScreenWidth - rightOperationViewWidth;
    self.signalImageView.frame = CGRectMake(20, self.meetingViewController.mainView.frame.size.height - 20 - 32, 34, 32);
    self.durationTimeTextField.frame = CGRectMake(self.signalImageView.frame.origin.x + self.signalImageView.frame.size.width + 10, self.signalImageView.frame.origin.y + 6, 65, 20);
    self.mainAudioLevelImageView.frame = CGRectMake(self.signalImageView.frame.origin.x, self.signalImageView.frame.origin.y - 20 - 10, self.mainAudioLevelImageView.frame.size.width, 20);
    self.videosBottomView.frame = CGRectMake(self.videosBottomView.frame.origin.x, self.videosBottomView.frame.origin.y, kScreenWidth, self.videosBottomView.frame.size.height);
    self.leftScrollButton.frame = CGRectMake(self.leftScrollButton.frame.origin.x, self.leftScrollButton.frame.origin.y, self.leftScrollButton.frame.size.width, self.videosBottomView.frame.size.height);
    self.rightScrollButton.frame = CGRectMake(self.videosBottomView.frame.size.width - self.rightScrollButton.frame.size.width, self.rightScrollButton.frame.origin.y, self.rightScrollButton.frame.size.width, self.videosBottomView.frame.size.height);
    self.downVideosBottomButton.frame = CGRectMake(self.leftScrollButton.frame.size.width, kCellSize, self.videosBottomView.frame.size.width - self.leftScrollButton.frame.size.width * 2, self.downVideosBottomButton.frame.size.height);
    
    CGFloat imageWidth = 15;
    self.rightContentView.frame = CGRectMake(kScreenWidth - rightOperationViewWidth - imageWidth, 0, rightOperationViewWidth + imageWidth, kScreenHeight);
    
    self.leftMessageButton.frame = CGRectMake(imageWidth, kScreenHeight - 30, rightOperationViewWidth/2, 30);
    self.rightMemberButton.frame = CGRectMake(rightOperationViewWidth/2+imageWidth, kScreenHeight - 30, rightOperationViewWidth/2, 30);
    self.rightMemberView.frame = CGRectMake(imageWidth, self.meetingViewController.mainView.frame.size.width - videoViewWidth + 1,
                                                                    self.meetingViewController.mainView.frame.size.width - videoViewWidth,
                                                                    self.meetingViewController.mainView.frame.size.height - (self.meetingViewController.mainView.frame.size.width - videoViewWidth) - 30);
    self.leftMessageView.frame = self.rightMemberView.frame;
    
    self.controlContentView.frame = CGRectMake(self.leftMessageButton.frame.origin.x, 0, self.leftMessageView.frame.size.width, self.leftMessageView.frame.size.width + 1);
    self.controlCollectionView.frame = CGRectMake(0, 0, self.controlContentView.bounds.size.width, self.leftMessageView.frame.size.width);
    self.controlScrollView.frame = self.controlCollectionView.bounds;
    
    self.tipMsgTextViewScrollView.frame = CGRectMake(0, 0, self.leftMessageView.frame.size.width, self.leftMessageView.frame.size.height);
    self.tipMsgTextView.frame = self.tipMsgTextViewScrollView.bounds;
    
    self.tipMsgTextViewScrollView.frame = CGRectMake(0, 0, self.leftMessageView.frame.size.width, self.leftMessageView.frame.size.height);
    self.tipMsgTextView.frame = self.tipMsgTextViewScrollView.bounds;
    
    self.rightMVScrollView.frame = self.rightMemberView.bounds;
    self.rightTableView.frame = self.rightMVScrollView.bounds;
    
    //添加隐藏/显示按钮
    [self.rightContentView addSubview:self.hideControlViewButton];
    LarkMeetingManager.isHideControlView = NO;
}

- (void)reloadMeetingViewToOriginalSize
{
    self.callingBreathImageView.frame = CGRectMake(kVideoWidth - 20 - 164, self.meetingViewController.mainView.frame.size.height - 20 - 164, 164, 164);
    self.callingHeadImageView.frame = CGRectMake((self.callingBreathImageView.frame.size.width-92)/2, (self.callingBreathImageView.frame.size.height-92)/2, 92, 92);
    self.callingHungUpButton.frame = CGRectMake(self.callingBreathImageView.frame.origin.x, self.callingBreathImageView.frame.origin.y - 30, 46, 46);
    self.callingAcceptButton.frame = CGRectMake(self.callingBreathImageView.frame.origin.x + self.callingBreathImageView.frame.size.width - 46, self.callingBreathImageView.frame.origin.y - 30, 46, 46);
    
    self.signalImageView.frame = CGRectMake(20, self.meetingViewController.mainView.frame.size.height - 20 - 32, 34, 32);
    self.durationTimeTextField.frame = CGRectMake(self.signalImageView.frame.origin.x + self.signalImageView.frame.size.width + 10, self.signalImageView.frame.origin.y + 6, 65, 20);
    self.mainAudioLevelImageView.frame = CGRectMake(self.signalImageView.frame.origin.x, self.signalImageView.frame.origin.y - 14, self.mainAudioLevelImageView.frame.size.width, 20);
    self.videosBottomView.frame = CGRectMake(self.videosBottomView.frame.origin.x, self.videosBottomView.frame.origin.y, kVideoWidth, self.videosBottomView.frame.size.height);
    self.leftScrollButton.frame = CGRectMake(self.leftScrollButton.frame.origin.x, self.leftScrollButton.frame.origin.y, self.leftScrollButton.frame.size.width, self.videosBottomView.frame.size.height);
    self.rightScrollButton.frame = CGRectMake(self.videosBottomView.frame.size.width - self.rightScrollButton.frame.size.width, 0, self.rightScrollButton.frame.size.width, self.videosBottomView.frame.size.height);
    self.downVideosBottomButton.frame = CGRectMake(self.leftScrollButton.frame.size.width, kCellSize, self.videosBottomView.frame.size.width - self.leftScrollButton.frame.size.width * 2, self.downVideosBottomButton.frame.size.height);
    
    self.rightContentView.frame = CGRectMake(kVideoWidth, 0, 840-kVideoWidth, self.meetingViewController.mainView.frame.size.height);
    self.leftMessageButton.frame = CGRectMake(0, 450, self.rightContentView.frame.size.width/2, 30);
    self.rightMemberButton.frame = CGRectMake(self.rightContentView.frame.size.width/2, 450, self.rightContentView.frame.size.width/2, 30);
    self.rightMemberView.frame = CGRectMake(0, self.meetingViewController.mainView.frame.size.width - kVideoWidth + 1,
                                                                    self.rightContentView.frame.size.width,
                                                                    self.rightContentView.frame.size.height - (self.meetingViewController.mainView.frame.size.width - kVideoWidth) - 30);
    self.leftMessageView.frame = self.rightMemberView.frame;
    
    self.controlContentView.frame = CGRectMake(self.leftMessageButton.frame.origin.x, 0, self.leftMessageView.frame.size.width, self.meetingViewController.mainView.frame.size.width - kVideoWidth + 1);
    self.controlCollectionView.frame = CGRectMake(0, 0, self.controlContentView.bounds.size.width, self.leftMessageView.frame.size.width);
    self.controlScrollView.frame = self.controlCollectionView.bounds;
    
    self.tipMsgTextViewScrollView.frame = CGRectMake(0, 0, self.leftMessageView.frame.size.width, self.leftMessageView.frame.size.height);
    self.tipMsgTextView.frame = self.tipMsgTextViewScrollView.bounds;
    
    self.rightMVScrollView.frame = self.rightMemberView.bounds;
    self.rightTableView.frame = self.rightMVScrollView.bounds;
    
    //移除隐藏/显示按钮
    [self.hideControlViewButton removeFromSuperview];
}

- (void)initCallingBreathView
{
    //呼叫呼吸
    self.callingBreathImageView = [[NSImageView alloc] initWithFrame:CGRectMake(kVideoWidth - 20 - 164, self.meetingViewController.mainView.frame.size.height - 20 - 164, 164, 164)];
    self.callingBreathImageView.image = [NSImage imageNamed:@"MeetingCalling1"];
    [self.meetingViewController.mainView addSubview:self.callingBreathImageView];
    
    //呼叫呼吸头像
    self.callingHeadImageView = [[NSImageView alloc] initWithFrame:CGRectMake((self.callingBreathImageView.frame.size.width-92)/2, (self.callingBreathImageView.frame.size.height-92)/2, 92, 92)];
    self.callingHeadImageView.wantsLayer = YES;
    self.callingHeadImageView.layer.cornerRadius = self.callingHeadImageView.frame.size.height / 2;
    self.callingHeadImageView.image = [NSImage imageNamed:@"AppIcon"];
//    [self.callingBreathImageView addSubview:self.callingHeadImageView];
    
    //呼吸挂断按钮
    self.callingHungUpButton = [[NSButton alloc] initWithFrame:CGRectMake(self.callingBreathImageView.frame.origin.x, self.callingBreathImageView.frame.origin.y - 30, 46, 46)];
    self.callingHungUpButton.bordered = NO;
    [self.callingHungUpButton setImage:[NSImage imageNamed:@"MeetingCallingHungUp"]];
    [(NSButtonCell *)self.callingHungUpButton.cell setHighlightsBy:NSNoCellMask];
    [self.callingHungUpButton setTarget:self.meetingViewController];
    [self.callingHungUpButton setAction:@selector(callingHungUpButtonPressed)];
    [self.meetingViewController.mainView addSubview:self.callingHungUpButton];
    
    //呼吸接听按钮
    self.callingAcceptButton = [[NSButton alloc] initWithFrame:CGRectMake(self.callingBreathImageView.frame.origin.x + self.callingBreathImageView.frame.size.width - 46, self.callingBreathImageView.frame.origin.y - 30, 46, 46)];
    self.callingAcceptButton.bordered = NO;
    [self.callingAcceptButton setImage:[NSImage imageNamed:@"MeetingCallingAccept"]];
    [(NSButtonCell *)self.callingAcceptButton.cell setHighlightsBy:NSNoCellMask];
    [self.callingAcceptButton setTarget:self.meetingViewController];
    [self.callingAcceptButton setAction:@selector(callingAcceptButtonPressed)];
    [self.meetingViewController.mainView addSubview:self.callingAcceptButton];
}

- (void)initVideoView
{
    //信号强度
    self.signalImageView = [[NSImageView alloc] initWithFrame:CGRectMake(20, self.meetingViewController.mainView.frame.size.height - 20 - 10, 60, 10)];
    self.signalImageView.image = [NSImage imageNamed:@"MeetingSignal0"];
    [self.meetingViewController.mainView addSubview:self.signalImageView];
    
    self.durationTimeTextField = [[NSTextField alloc] initWithFrame:CGRectMake(self.signalImageView.frame.origin.x + self.signalImageView.frame.size.width + 10, self.signalImageView.frame.origin.y - 5, 65, 20)];
    self.durationTimeTextField.stringValue = @"00:00";
    self.durationTimeTextField.bordered = NO;
    self.durationTimeTextField.editable = NO;
    self.durationTimeTextField.alignment = NSTextAlignmentLeft;
    self.durationTimeTextField.font = [NSFont systemFontOfSize:14.0];
    self.durationTimeTextField.textColor = [NSColor whiteColor];
    self.durationTimeTextField.backgroundColor = [NSColor clearColor];
    [self.meetingViewController.mainView addSubview:self.durationTimeTextField];
    
    self.mainAudioLevelImageView = [[NSImageView alloc] initWithFrame:CGRectMake(self.signalImageView.frame.origin.x, self.signalImageView.frame.origin.y - 20 - 10, self.signalImageView.frame.size.width, 20)];
    [self.meetingViewController.mainView addSubview:self.mainAudioLevelImageView];
    
    //底部视频View
    self.videosBottomView = [[BaseView alloc] initWithFrame:CGRectMake(0, 0, kVideoWidth, 105)];
    self.videosBottomView.backgroundColor = kVideoViewColor;
    [self.meetingViewController.mainView addSubview:self.videosBottomView];
    
    //左移动视频按钮
    self.leftScrollButton = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 22, self.videosBottomView.frame.size.height)];
    self.leftScrollButton.bordered = NO;
    [self.leftScrollButton setImage:[NSImage imageNamed:@"MeetingLeftScrollButton"]];
    [(NSButtonCell *)self.leftScrollButton.cell setHighlightsBy:NSNoCellMask];
    [self.leftScrollButton setTarget:self.meetingViewController];
    [self.leftScrollButton setAction:@selector(leftScrollButtonPressed)];
    [self.videosBottomView addSubview:self.leftScrollButton];
    
    //右移动视频按钮
    self.rightScrollButton = [[NSButton alloc] initWithFrame:CGRectMake(self.videosBottomView.frame.size.width - 22, 0, 22, self.videosBottomView.frame.size.height)];
    self.rightScrollButton.bordered = NO;
    [self.rightScrollButton setImage:[NSImage imageNamed:@"MeetingRightScrollButton"]];
    [(NSButtonCell *)self.rightScrollButton.cell setHighlightsBy:NSNoCellMask];
    [self.rightScrollButton setTarget:self.meetingViewController];
    [self.rightScrollButton setAction:@selector(rightScrollButtonPressed)];
    [self.videosBottomView addSubview:self.rightScrollButton];
    
    //向下隐藏/向上显示视频View
    self.downVideosBottomButton = [[NSButton alloc] initWithFrame:CGRectMake(22, kCellSize, self.videosBottomView.frame.size.width - 44, 25)];
    self.downVideosBottomButton.bordered = NO;
    [self.downVideosBottomButton setImage:[NSImage imageNamed:@"MeetingDownVideoBottomButton"]];
    [(NSButtonCell *)self.downVideosBottomButton.cell setHighlightsBy:NSNoCellMask];
    [self.downVideosBottomButton setTarget:self.meetingViewController];
    [self.downVideosBottomButton setAction:@selector(downVideosBottomButtonPressed)];
    [self.videosBottomView addSubview:self.downVideosBottomButton];
    
    self.switchPageViewControl = [[SwitchPageViewControl alloc] initWithViewBuilder:self.meetingViewController];
    self.switchPageViewControl.delegate = self.meetingViewController.meetingSwitchPageViewDelegateSource;
    self.switchPageViewControl.dataSource = self.meetingViewController.meetingSwitchPageViewDelegateSource;
    
    //隐藏/显示右侧控制栏按钮
    self.hideControlViewButton = [[NSButton alloc] initWithFrame:CGRectMake(0, (kScreenHeight-100)/2, 15, 100)];
    self.hideControlViewButton.bordered = NO;
    [self.hideControlViewButton setImage:[NSImage imageNamed:@"MeetingHideControlViewRight"]];
    //    [(NSButtonCell *)self.hideControlViewButton.cell setHighlightsBy:NSNoCellMask];
    [(NSButtonCell *)self.hideControlViewButton.cell setHighlightsBy:NSContentsCellMask];
    [self.hideControlViewButton setTarget:self.meetingViewController];
    [self.hideControlViewButton setAction:@selector(hideControlViewButtonPressed)];
}

- (void)initMeetingControlView
{
    self.rightContentView = [[NSView alloc] initWithFrame:CGRectMake(kVideoWidth, 0, 840-kVideoWidth, self.meetingViewController.mainView.frame.size.height)];
    [self.meetingViewController.mainView addSubview:self.rightContentView];
    
    //左侧会场消息按钮
    self.leftMessageButton = [[NSButton alloc] initWithFrame:CGRectMake(0, 450, self.rightContentView.frame.size.width/2, 30)];
    self.leftMessageButton.bezelStyle = NSRoundedBezelStyle;
    self.leftMessageButton.bordered = NO;
    [self.leftMessageButton setTitle:NSLocalizedString(@"meeting_meet_message", nil)];
    self.leftMessageButton.hidden = NO;
    self.leftMessageButton.tag = 100;
    self.leftMessageButton.alignment = NSTextAlignmentCenter;
    self.leftMessageButton.transparent = NO;
    self.leftMessageButton.state = NSOffState;
    self.leftMessageButton.highlighted = NO;
    [self.leftMessageButton setButtonType:NSButtonTypeMomentaryPushIn];
    //self.leftMessageButton.image = [NSImage imageNamed:@"MeetingHungupButton"];
    [self.leftMessageButton setTarget:self.meetingViewController];
    [self.leftMessageButton setAction:@selector(leftMessageButtonPressed)];
    [self.rightContentView addSubview:self.leftMessageButton];
    self.leftMessageButton.wantsLayer = YES;
    self.leftMessageButton.layer.backgroundColor = kThemeColor.CGColor;
    
    //右侧与会成员按钮
    self.rightMemberButton = [[NSButton alloc] initWithFrame:CGRectMake(self.rightContentView.frame.size.width/2, 450, self.rightContentView.frame.size.width/2, 30)];
    self.rightMemberButton.bezelStyle = NSRoundedBezelStyle;
    self.rightMemberButton.bordered = NO;
    [self.rightMemberButton setTitle:NSLocalizedString(@"meeting_meet_member", nil)];
    self.rightMemberButton.hidden = NO;
    self.rightMemberButton.tag = 200;
    self.rightMemberButton.alignment = NSTextAlignmentCenter;
    self.rightMemberButton.transparent = NO;
    self.rightMemberButton.state = NSOffState;
    self.rightMemberButton.highlighted = NO;
    [self.rightMemberButton setButtonType:NSButtonTypeMomentaryPushIn];
    //self.rightMemberButton.image = [NSImage imageNamed:@"MeetingHungupButton"];
    [self.rightMemberButton setTarget:self.meetingViewController];
    [self.rightMemberButton setAction:@selector(rightMemberButtonPressed)];
    [self.rightContentView addSubview:self.rightMemberButton];
    self.rightMemberButton.wantsLayer = YES;
    self.rightMemberButton.layer.backgroundColor = [NSColor lightGrayColor].CGColor;
    
    //与会成员View
    self.rightMemberView = [[NSView alloc] initWithFrame:CGRectMake(0, self.meetingViewController.mainView.frame.size.width - kVideoWidth + 1,
                                                                    self.rightContentView.frame.size.width,
                                                                    self.rightContentView.frame.size.height - (self.meetingViewController.mainView.frame.size.width - kVideoWidth) - 30)];
    
    self.rightMemberView.wantsLayer = YES;
    [self.rightContentView addSubview:self.rightMemberView];
    
    //会场消息View
    self.leftMessageView = [[NSView alloc] initWithFrame:self.rightMemberView.frame];
    self.leftMessageView.wantsLayer = YES;
    self.leftMessageView.layer.backgroundColor = [NSColor whiteColor].CGColor;
    [self.rightContentView addSubview:self.leftMessageView];
}

- (void)initOperationCollectionView
{
    self.controlContentView = [[NSView alloc] initWithFrame:CGRectMake(self.leftMessageButton.frame.origin.x, 0, self.leftMessageView.frame.size.width, self.meetingViewController.mainView.frame.size.width - kVideoWidth + 1)];
    self.controlContentView.wantsLayer = YES;
    self.controlContentView.layer.backgroundColor = [NSColor lightGrayColor].CGColor;
    [self.rightContentView addSubview:self.controlContentView];
    
    //CollectionViewLayout
    NSCollectionViewFlowLayout *layout = [[NSCollectionViewFlowLayout alloc] init];
    layout.scrollDirection = NSCollectionViewScrollDirectionVertical;
    layout.minimumLineSpacing = 1;
    layout.minimumInteritemSpacing = 1;
    layout.itemSize = NSMakeSize(66, 66);
    layout.sectionInset = NSEdgeInsetsMake(0, 0, 0, 0);
    
    //CollectionView
    self.controlCollectionView = [[NSCollectionView alloc] initWithFrame:CGRectMake(0, 0, self.controlContentView.bounds.size.width, self.leftMessageView.frame.size.width)];
    self.controlCollectionView.collectionViewLayout = layout;
    self.controlCollectionView.wantsLayer = YES;
    self.controlCollectionView.layer.backgroundColor = [NSColor lightGrayColor].CGColor;
    [self.controlCollectionView registerClass:[LeftMVControlCollectionViewItem class] forItemWithIdentifier:@"controlCollectionViewItem"];
    self.controlCollectionView.delegate = self.meetingViewController.leftMVControlCollectionViewDelegateSource;
    self.controlCollectionView.dataSource = self.meetingViewController.leftMVControlCollectionViewDelegateSource;
    [self.controlCollectionView setSelectable:YES];
    
    self.controlScrollView = [[NSScrollView alloc] initWithFrame:self.controlCollectionView.bounds];
    self.controlScrollView.hasVerticalScroller = YES;
    self.controlScrollView.autohidesScrollers = YES;
    self.controlScrollView.borderType = NSNoBorder;
    self.controlScrollView.scrollerStyle = NSScrollerStyleOverlay;
    
    [self.controlScrollView setDocumentView:self.controlCollectionView];
    [self.controlContentView addSubview:self.controlScrollView];
}

- (void)initLeftMessageContentView
{
    /*
    //声音按钮
    self.leftMVVoiceButton = [[NSButton alloc] initWithFrame:CGRectMake(6, 326, 24, 24)];
    self.leftMVVoiceButton.bezelStyle = NSRoundedBezelStyle;
    self.leftMVVoiceButton.bordered = NO;
    self.leftMVVoiceButton.transparent = NO;
    self.leftMVVoiceButton.highlighted = NO;
    [self.leftMVVoiceButton setButtonType:NSButtonTypeMomentaryPushIn];
    self.leftMVVoiceButton.image = [NSImage imageNamed:@"MeetingMuteOpenMicphone"];
//    self.leftMVVoiceButton.wantsLayer = YES;
//    self.leftMVVoiceButton.layer.backgroundColor = [NSColor blueColor].CGColor;
    [self.leftMVVoiceButton setTarget:self.meetingViewController];
    [self.leftMVVoiceButton setAction:@selector(leftMVVoiceButtonPressed)];
//    [self.operationContentView addSubview:self.leftMVVoiceButton];
    
    //文字输入
    NSScrollView *meeageTextFieldScrollView = [[NSScrollView alloc] initWithFrame:CGRectMake(36, 326, 220, 26)];
    meeageTextFieldScrollView.hasVerticalScroller = YES;
    meeageTextFieldScrollView.borderType = NSNoBorder;
    meeageTextFieldScrollView.scrollerStyle = NSScrollerStyleOverlay;
    
    self.meeageTextField = [[NSTextField alloc] initWithFrame:meeageTextFieldScrollView.bounds];
    [self.meeageTextField setFont:[NSFont systemFontOfSize:18]];
    [self.meeageTextField setDrawsBackground:NO];
    self.meeageTextField.wantsLayer = YES;
    
//    [meeageTextFieldScrollView setDocumentView:self.meeageTextField];
//    [self.operationContentView addSubview:meeageTextFieldScrollView];
    
    //发送消息按钮
    self.leftMVSendButton = [[NSButton alloc] initWithFrame:CGRectMake(264, 326, 50, 26)];
    self.leftMVSendButton.bezelStyle = NSBezelStyleRoundRect;
    self.leftMVSendButton.bordered = NO;
    [self.leftMVSendButton setTitle:@"发送"];
    self.leftMVSendButton.alignment = NSTextAlignmentCenter;
    self.leftMVSendButton.transparent = NO;
    self.leftMVSendButton.state = NSOffState;
    self.leftMVSendButton.highlighted = YES;
    [self.leftMVSendButton setButtonType:NSButtonTypeMomentaryPushIn];
    [self.leftMVSendButton setTarget:self.meetingViewController];
    [self.leftMVSendButton setAction:@selector(leftMVSendButtonPressed)];
    self.leftMVSendButton.wantsLayer = YES;
    self.leftMVSendButton.layer.backgroundColor = kThemeColor.CGColor;
    self.leftMVSendButton.layer.cornerRadius = 4.0;
//    [self.operationContentView addSubview:self.leftMVSendButton];
    */
    ///////////////////////////
    //滚动消息TextView
    self.tipMsgTextViewScrollView = [[NSScrollView alloc] initWithFrame:CGRectMake(0, 0, self.leftMessageView.frame.size.width, self.leftMessageView.frame.size.height)];
    self.tipMsgTextViewScrollView.hasVerticalScroller = YES;
    self.tipMsgTextViewScrollView.borderType = NSNoBorder;
    self.tipMsgTextViewScrollView.scrollerStyle = NSScrollerStyleOverlay;
    
    self.tipMsgTextView = [[NSTextView alloc] initWithFrame:self.tipMsgTextViewScrollView.bounds];
    [self.tipMsgTextView setFont:[NSFont systemFontOfSize:12]];
    [self.tipMsgTextView setDrawsBackground:NO];
    self.tipMsgTextView.alignment = NSCenterTextAlignment;
    self.tipMsgTextView.textColor = [NSColor lightGrayColor];
    
    [self.tipMsgTextViewScrollView setDocumentView:self.tipMsgTextView];
    [self.leftMessageView addSubview:self.tipMsgTextViewScrollView];
}

- (void)initRightMemberContentView
{
    self.rightMVScrollView = [[NSScrollView alloc] initWithFrame:self.rightMemberView.bounds];
    self.rightMVScrollView.hasVerticalScroller = YES;
    self.rightMVScrollView.borderType = NSNoBorder;
    self.rightMVScrollView.scrollerStyle = NSScrollerStyleOverlay;
    
    self.rightTableView = [[NSTableView alloc] initWithFrame:self.rightMVScrollView.bounds];
    self.rightTableView.focusRingType = NSFocusRingTypeNone;
    self.rightTableView.selectionHighlightStyle = NSTableViewSelectionHighlightStyleRegular;
    self.rightTableView.headerView.frame = NSZeroRect;
//    self.rightTableView.gridStyleMask = NSTableViewSolidHorizontalGridLineMask;
//    self.rightTableView.gridColor = [NSColor clearColor];
    self.rightTableView.usesAlternatingRowBackgroundColors = NO;
    self.rightTableView.allowsMultipleSelection = NO;
    [self.rightTableView registerNib:[[NSNib alloc] initWithNibNamed:@"RightMVTableViewCellView" bundle:nil] forIdentifier:@"RightMVTableViewCellView"];
    
    self.rightTableView.delegate = self.meetingViewController.rightMVTableViewDelegateSource;
    self.rightTableView.dataSource = self.meetingViewController.rightMVTableViewDelegateSource;
    self.rightTableView.target = self.meetingViewController;
    self.rightMVScrollView.contentView.documentView = self.rightTableView;
    [self.rightMemberView addSubview:self.rightMVScrollView];
    
    NSTableColumn *columen1 = [[NSTableColumn alloc] initWithIdentifier:@"columen1"];
    columen1.minWidth = self.rightTableView.frame.size.width+15;
    columen1.resizingMask = NSTableColumnUserResizingMask;
    [self.rightTableView addTableColumn:columen1];
}

- (void)initConfirmMessageWindow
{
    self.confirmMessageWindow = [[NSWindow alloc] initWithContentRect:CGRectMake(0, 0, 280, 160) styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:YES];
    
    NSButton *yesButton = [[NSButton alloc] initWithFrame:CGRectMake(20, 10, 110, 30)];
    yesButton.bezelStyle = NSBezelStyleRounded;
    yesButton.bordered = YES;
    yesButton.font = [NSFont systemFontOfSize:14.0];
    [yesButton setTitle:NSLocalizedString(@"meeting_confirm_ok", nil)];
    yesButton.hidden = NO;
    yesButton.alignment = NSTextAlignmentCenter;
    yesButton.transparent = NO;
    yesButton.state = NSOffState;
    yesButton.highlighted = NO;
    [yesButton setButtonType:NSButtonTypeMomentaryPushIn];
    [yesButton setTarget:self.meetingViewController];
    [yesButton setAction:@selector(messageAlertYes)];
    [self.confirmMessageWindow.contentView addSubview:yesButton];
    
    NSButton *noButton = [[NSButton alloc] initWithFrame:CGRectMake(150, 10, 110, 30)];
    noButton.bezelStyle = NSBezelStyleRounded;
    noButton.bordered = YES;
    noButton.font = [NSFont systemFontOfSize:14.0];
    [noButton setTitle:NSLocalizedString(@"meeting_confirm_cancel", nil)];
    noButton.hidden = NO;
    noButton.alignment = NSTextAlignmentCenter;
    noButton.transparent = NO;
    noButton.state = NSOffState;
    noButton.highlighted = NO;
    [noButton setButtonType:NSButtonTypeMomentaryPushIn];
    [noButton setTarget:self.meetingViewController];
    [noButton setAction:@selector(messageAlertNo)];
    [self.confirmMessageWindow.contentView addSubview:noButton];
}

- (void)initAlertMessageWindow
{
    self.alertMessageWindow = [[NSWindow alloc] initWithContentRect:CGRectMake(0, 0, 280, 160) styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:YES];
    
    NSButton *yesButton = [[NSButton alloc] initWithFrame:CGRectMake((self.alertMessageWindow.frame.size.width - 110 ) / 2, 10, 110, 30)];
    yesButton.bezelStyle = NSBezelStyleRounded;
    yesButton.bordered = YES;
    yesButton.font = [NSFont systemFontOfSize:14.0];
    [yesButton setTitle:NSLocalizedString(@"meeting_confirm_close", nil)];
    yesButton.hidden = NO;
    yesButton.alignment = NSTextAlignmentCenter;
    yesButton.transparent = NO;
    yesButton.state = NSOffState;
    yesButton.highlighted = NO;
    [yesButton setButtonType:NSButtonTypeMomentaryPushIn];
    [yesButton setTarget:self.meetingViewController];
    [yesButton setAction:@selector(messageAlertSingleYes)];
    [self.alertMessageWindow.contentView addSubview:yesButton];
}

- (void)initConfirmMessagePanel
{
    //提示窗口
    self.confirmMessagePanel = [[NSPanel alloc] initWithContentRect:CGRectMake(0, 0, 280, 160) styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreNonretained defer:YES];
    self.confirmMessagePanel.floatingPanel = YES;
    [self.confirmMessagePanel center];
    
    NSButton *yesButton = [[NSButton alloc] initWithFrame:CGRectMake(20, 10, 110, 30)];
    yesButton.bezelStyle = NSBezelStyleRounded;
    yesButton.bordered = YES;
    yesButton.font = [NSFont systemFontOfSize:14.0];
    [yesButton setTitle:NSLocalizedString(@"meeting_confirm_ok", nil)];
    yesButton.hidden = NO;
    yesButton.alignment = NSTextAlignmentCenter;
    yesButton.transparent = NO;
    yesButton.state = NSOffState;
    yesButton.highlighted = NO;
    [yesButton setButtonType:NSButtonTypeMomentaryPushIn];
    [yesButton setTarget:self.meetingViewController];
    [yesButton setAction:@selector(messageAlertYes)];
    [self.confirmMessagePanel.contentView addSubview:yesButton];
    
    NSButton *noButton = [[NSButton alloc] initWithFrame:CGRectMake(150, 10, 110, 30)];
    noButton.bezelStyle = NSBezelStyleRounded;
    noButton.bordered = YES;
    noButton.font = [NSFont systemFontOfSize:14.0];
    [noButton setTitle:NSLocalizedString(@"meeting_confirm_cancel", nil)];
    noButton.hidden = NO;
    noButton.alignment = NSTextAlignmentCenter;
    noButton.transparent = NO;
    noButton.state = NSOffState;
    noButton.highlighted = NO;
    [noButton setButtonType:NSButtonTypeMomentaryPushIn];
    [noButton setTarget:self.meetingViewController];
    [noButton setAction:@selector(messageAlertNo)];
    [self.confirmMessagePanel.contentView addSubview:noButton];
}

- (void)initAlertMessagePanel
{
    //提示窗口
    self.alertMessagePanel = [[NSPanel alloc] initWithContentRect:CGRectMake(0, 0, 280, 160) styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreNonretained defer:YES];
    self.alertMessagePanel.floatingPanel = YES;
    [self.alertMessagePanel center];
    
    NSButton *yesButton = [[NSButton alloc] initWithFrame:CGRectMake((self.alertMessagePanel.frame.size.width - 110 ) / 2, 10, 110, 30)];
    yesButton.bezelStyle = NSBezelStyleRounded;
    yesButton.bordered = YES;
    yesButton.font = [NSFont systemFontOfSize:14.0];
    [yesButton setTitle:NSLocalizedString(@"meeting_confirm_close", nil)];
    yesButton.hidden = NO;
    yesButton.alignment = NSTextAlignmentCenter;
    yesButton.transparent = NO;
    yesButton.state = NSOffState;
    yesButton.highlighted = NO;
    [yesButton setButtonType:NSButtonTypeMomentaryPushIn];
    [yesButton setTarget:self.meetingViewController];
    [yesButton setAction:@selector(messageAlertSingleYes)];
    [self.alertMessagePanel.contentView addSubview:yesButton];
}

- (void)initScreenShareMessageTextField
{
    self.screenShareMessageTextField = [[NSTextField alloc] initWithFrame:CGRectMake(0, (kVideoHeight - 20 ) / 2, kVideoWidth, 20)];
    self.screenShareMessageTextField.stringValue = NSLocalizedString(@"meeting_share_screen", nil);
    self.screenShareMessageTextField.bordered = NO;
    self.screenShareMessageTextField.editable = NO;
    self.screenShareMessageTextField.alignment = NSTextAlignmentCenter;
    self.screenShareMessageTextField.font = [NSFont systemFontOfSize:18.0];
    self.screenShareMessageTextField.textColor = [NSColor whiteColor];
    self.screenShareMessageTextField.backgroundColor = [NSColor clearColor];
}

- (void)initWhiteBoardWebView
{
    self.whiteBoardWebView = [[WebView alloc] initWithFrame:CGRectMake(0, 0, kVideoWidth, kVideoHeight)];
//    [self.meetingViewController.mainView addSubview:self.whiteBoardWebView];
//    [[self.whiteBoardWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com"]]];
}

- (void)initAVInfoPanel
{
    self.avInfoPanel = [[NSPanel alloc] initWithContentRect:CGRectMake(0, 0, 480, 480) styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreNonretained defer:YES];
    self.avInfoPanel.title = @"信息统计";
    self.avInfoPanel.floatingPanel = YES;
    [self.avInfoPanel center];
    
    //网络探测
    NSScrollView *localDataScrollView = [[NSScrollView alloc] initWithFrame:CGRectMake(0, 417, self.avInfoPanel.frame.size.width, 63)];
    localDataScrollView.hasVerticalScroller = NO;
    localDataScrollView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
    [self.avInfoPanel.contentView addSubview:localDataScrollView];
    
    self.localDataTableView = [[NSTableView alloc] init];
    self.localDataTableView.frame = CGRectMake(0, 0, localDataScrollView.frame.size.width, localDataScrollView.frame.size.height);
    self.localDataTableView.focusRingType = NSFocusRingTypeNone;
    self.localDataTableView.selectionHighlightStyle = NSTableViewSelectionHighlightStyleRegular;
    self.localDataTableView.headerView.frame = CGRectMake(0, 0, 160, 23);
    self.localDataTableView.gridStyleMask = NSTableViewSolidHorizontalGridLineMask;
    self.localDataTableView.usesAlternatingRowBackgroundColors = YES;
    self.localDataTableView.allowsMultipleSelection = NO;
    self.localDataTableView.tag = 100;
    self.localDataTableView.delegate = self.meetingViewController.avDataInfoTableViewDelegateSource;
    self.localDataTableView.dataSource = self.meetingViewController.avDataInfoTableViewDelegateSource;
//    self.localDataTableView.target = self;
//    [self.localDataTableView setAction:@selector(selectClick:)];
    localDataScrollView.contentView.documentView = self.localDataTableView;
    
    NSTableColumn *columen00 = [[NSTableColumn alloc] initWithIdentifier:@"columen00"];
    columen00.headerCell.title = @"通道名称";
    columen00.headerCell.alignment = NSTextAlignmentCenter;
    columen00.minWidth = 160.0;
    columen00.resizingMask = NSTableColumnUserResizingMask;
    [self.localDataTableView addTableColumn:columen00];
    
    NSTableColumn *columen01 = [[NSTableColumn alloc] initWithIdentifier:@"columen01"];
    columen01.headerCell.title = @"码率";
    columen01.headerCell.alignment = NSTextAlignmentCenter;
    columen01.minWidth = 160.0;
    columen01.resizingMask = NSTableColumnUserResizingMask;
    [self.localDataTableView addTableColumn:columen01];
    
    NSTableColumn *columen02 = [[NSTableColumn alloc] initWithIdentifier:@"columen02"];
    columen02.headerCell.title = @"音/视频往返延时(ms)";
    columen02.headerCell.alignment = NSTextAlignmentCenter;
    columen02.minWidth = 160.0;
    columen02.resizingMask = NSTableColumnUserResizingMask;
    [self.localDataTableView addTableColumn:columen02];
    
    
    //与会者
    NSScrollView *memberDataScrollView = [[NSScrollView alloc] initWithFrame:CGRectMake(0, 0, self.avInfoPanel.frame.size.width, 400)];
    memberDataScrollView.hasVerticalScroller = NO;
    memberDataScrollView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
    [self.avInfoPanel.contentView addSubview:memberDataScrollView];
    
    self.memberDataTableView = [[NSTableView alloc] init];
    self.memberDataTableView.frame = CGRectMake(0, 0, memberDataScrollView.frame.size.width, memberDataScrollView.frame.size.height);
    self.memberDataTableView.focusRingType = NSFocusRingTypeNone;
    self.memberDataTableView.selectionHighlightStyle = NSTableViewSelectionHighlightStyleRegular;
    self.memberDataTableView.headerView.frame = CGRectMake(0, 0, 60, 23);
    self.memberDataTableView.gridStyleMask = NSTableViewSolidHorizontalGridLineMask;
    self.memberDataTableView.usesAlternatingRowBackgroundColors = YES;
    self.memberDataTableView.allowsMultipleSelection = NO;
    self.memberDataTableView.tag = 200;
    self.memberDataTableView.delegate = self.meetingViewController.avDataInfoTableViewDelegateSource;
    self.memberDataTableView.dataSource = self.meetingViewController.avDataInfoTableViewDelegateSource;
    memberDataScrollView.contentView.documentView = self.memberDataTableView;
    
    NSTableColumn *columen10 = [[NSTableColumn alloc] initWithIdentifier:@"columen10"];
    columen10.headerCell.title = @"用户";
    columen10.headerCell.alignment = NSTextAlignmentCenter;
    columen10.width = 100.0;
    columen10.minWidth = 80.0;
    columen10.resizingMask = NSTableColumnUserResizingMask;
    [self.memberDataTableView addTableColumn:columen10];
    
    NSTableColumn *columen11 = [[NSTableColumn alloc] initWithIdentifier:@"columen11"];
    columen11.headerCell.title = @"通道名称";
    columen11.headerCell.alignment = NSTextAlignmentCenter;
    columen11.width = 70.0;
    columen11.minWidth = 40.0;
    columen11.resizingMask = NSTableColumnUserResizingMask;
    [self.memberDataTableView addTableColumn:columen11];
    
    NSTableColumn *columen12 = [[NSTableColumn alloc] initWithIdentifier:@"columen12"];
    columen12.headerCell.title = @"Codec";
    columen12.headerCell.alignment = NSTextAlignmentCenter;
    columen12.width = 40.0;
    columen12.minWidth = 40.0;
    columen12.resizingMask = NSTableColumnUserResizingMask;
    [self.memberDataTableView addTableColumn:columen12];
    
    NSTableColumn *columen13 = [[NSTableColumn alloc] initWithIdentifier:@"columen13"];
    columen13.headerCell.title = @"分辨率";
    columen13.headerCell.alignment = NSTextAlignmentCenter;
    columen13.width = 90.0;
    columen13.minWidth = 90.0;
    columen13.resizingMask = NSTableColumnUserResizingMask;
    [self.memberDataTableView addTableColumn:columen13];
    
    NSTableColumn *columen14 = [[NSTableColumn alloc] initWithIdentifier:@"columen14"];
    columen14.headerCell.title = @"帧率";
    columen14.headerCell.alignment = NSTextAlignmentCenter;
    columen14.width = 30.0;
    columen14.minWidth = 30.0;
    columen14.resizingMask = NSTableColumnUserResizingMask;
    [self.memberDataTableView addTableColumn:columen14];
    
    NSTableColumn *columen15 = [[NSTableColumn alloc] initWithIdentifier:@"columen15"];
    columen15.headerCell.title = @"码率";
    columen15.headerCell.alignment = NSTextAlignmentCenter;
    columen15.width = 80.0;
    columen15.minWidth = 80.0;
    columen15.resizingMask = NSTableColumnUserResizingMask;
    [self.memberDataTableView addTableColumn:columen15];
    
    NSTableColumn *columen16 = [[NSTableColumn alloc] initWithIdentifier:@"columen16"];
    columen16.headerCell.title = @"丢包率%";
    columen16.headerCell.alignment = NSTextAlignmentCenter;
    columen16.width = 50.0;
    columen16.minWidth = 50.0;
    columen16.resizingMask = NSTableColumnUserResizingMask;
    [self.memberDataTableView addTableColumn:columen16];
}

@end
